package icasue.reflect.handles.object;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;


class Tools{

    /**
     * copy from base_model [base.wareable.check.CommonCheck]
     */
    static class Check {
        public static boolean nullStrings(String... strings){
            if(strings == null || strings.length<=0) {
                return true;
            }
            for (String string : strings) {
                if(string == null || "".equals(string.trim())) {
                    return true;
                }
            }
            return false;
        }

        public static boolean nullList(List<?> list){
            if(list == null || list.size()<=0) {
                return true;
            }
            return false;
        }

        public static boolean fullList(List<?> list){
            if(nullList(list))
                return false;
            for (Object obj : list) {
                if(obj == null)
                    return false;
            }
            return true;
        }

        public static boolean nullSet(Set<?> set){
            if(set == null || set.size()<=0) {
                return true;
            }
            return false;
        }

        public static boolean nullMap (Map map){
            if(map == null || map.size()<=0) {
                return true;
            }
            return false;
        }

        public static List necessaryListNotNull(List<?> list){
            return nullList(list) ? new ArrayList() : list;
        }

        public static boolean nullArray(Object[] array){
            if(array == null) {
                return true;
            }
            for (Object o : array) {
                if(o == null || (o instanceof String && "".equals(((String)o).trim()))) {
                    return true;
                }
            }
            return false;
        }

        public static List<String> dealNullList(List<String> list){
            return nullList(list) ? new ArrayList<>() : list;
        }


        public static List<String> dealNullListForQuery(List<String> list){
            List<String> notNullForQuery = new ArrayList<>();
            notNullForQuery.add("");
            return nullList(list) ? notNullForQuery : list;
        }

        public  static <T> List<T> dealNullListCasue(List<T> list){
            return nullList(list) ? new ArrayList<>() : list;
        }

        public static boolean nullObjects(Object... objs){
            if(objs == null || objs.length<=0) {
                return true;
            }
            for (Object obj : objs) {
                if(obj == null) {
                    return true;
                }
            }
            return false;
        }

        public static boolean fullObjects(Object... objs){
            if(nullObjects(objs))
                return false;
            for (Object obj : objs) {
                if(obj == null)
                    return false;
            }
            return true;
        }

        public static String confirmString(Object obj){
            return obj == null ? "" : (obj instanceof String ? obj.toString() : "");
        }

    }
}

